package splab.ufcg.edu.br.trace.testlink.util;

import splab.ufcg.edu.br.trace.entities.AbstractSystemProperties;
import splab.ufcg.edu.br.trace.exceptions.PropertiesException;

public class ConnectionProperties extends AbstractSystemProperties {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1995818392767857782L;

	private final String USERNAME_PROPERTIE = "db.user";
	private final String PASSWORD_PROPERTIE = "db.passwd";
	private final String DB_NAME_PROPERTIE = "db.name";
	private final String URL_PROPERTIE = "url.connection";

	private String username;

	private String dbname;

	private String password;

	private String url;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getDbname() {
		return dbname;
	}

	public void setDbname(String dbname) {
		this.dbname = dbname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	/**
	 * Default ConectionProperties constructor
	 * 
	 * @param String
	 *            path to properties file
	 * @throws PropertiesException
	 *             if cannot read properties files
	 */
	public ConnectionProperties(String path) throws PropertiesException {
		super(path);
	}

	@Override
	public void setPropertyByKey(String key, String value, String line)
			throws PropertiesException {
		switch (key) {
		case USERNAME_PROPERTIE:
			this.setUsername(value);
			break;

		case PASSWORD_PROPERTIE:
			this.setPassword(value);
			break;

		case DB_NAME_PROPERTIE:
			this.setDbname(value);
			break;

		case URL_PROPERTIE:
			this.setUrl(value);
			break;

		default:
			StringBuilder message = new StringBuilder();
			message.append("Cannot read propertie in line: ");
			message.append(line);
			throw new PropertiesException(message.toString());

		}
	}

}
